package Dao.Impl;

import Bean.Cart;
import Dao.BasicDao;
import Dao.CartDao;

import java.util.List;

public class CartDaoImpl<T> extends BasicDao implements CartDao {
    @Override
    public void InsertCart(Integer UserID,Integer FurnId) {
        String sql = "insert into CartFurn (userid, furnid, id, amount) values (?,?,null,1);";
        dml(sql, UserID, FurnId);
    }

    @Override
    public List getAllCartFurn(Integer UserID, Class aClass) {
        String sql = "select distinct FurnId,amount from CartFurn where UserId = ?;";
       return getSomeQuery(sql,aClass,UserID);
    }

    @Override
    public T isCartFurn(Integer UserID, Integer FurnID, Class tClass) {
       String sql ="select FurnId,amount from CartFurn where UserId=? and FurnId=?;";
       return (T) selectOne(sql,tClass,UserID,FurnID);
    }

    @Override
    public boolean deleterSomeCart(Integer UserID, Integer FurnID) {
        String sql ="delete from CartFurn where UserId=? and FurnId =?;";
        return dml(sql,UserID,FurnID);
    }

    @Override
    public void deterAllCart(Integer UserID) {
        String sql ="delete from CartFurn where UserId=? ;";
        dml(sql,UserID);
    }

    @Override
    public void SetCartSize(Integer UserID, Integer FurnID, Integer Size) {
        String sql= "update CartFurn set amount  = ? where FurnId = ? and UserId = ?;";
        dml(sql,Size,FurnID,UserID);
    }

    @Override
    public Integer getCount(Integer userId) {
        String sql= "select count(*) from CartFurn where UserId = ?;";
        Integer count = getCount(sql, userId);
        if (count == -1){
            count = 0;
        }
        return count;
    }
}
